import SoundsManager from "./soundmanager";

export default class SoundButton extends Laya.Sprite {

    constructor(isMusic,name) {
        super();
        this.isMusic = isMusic;
        this.callback = this.changeState;
        this.name = name;
        
    }
    changeState(e) {
        var status = !(this.isMusic ? SoundsManager.instance.isMusicEnabled : SoundsManager.instance.isSoundEnabled);
        this.isMusic ? SoundsManager.instance.setMusic(status) : SoundsManager.instance.setSound(status);
        this.refresh();
    };
    refresh() {
        var enabled = this.isMusic ? SoundsManager.instance.isMusicEnabled : SoundsManager.instance.isSoundEnabled;
        this.loadImage(this.name+(enabled?1:0)+'.png');
    };
}